#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


Exercise 1.2.29: Day of the week

Syntax:
python day_of_the_week.py <month> <day> <year>
python day_of_the_week.py 11 23 2014


Notes:
int(sys.argv[1]) == Integer.parseInt(args[0])

sys is a required import here in order to use command line arguments.
https://docs.python.org/2/tutorial/stdlib.html

'''

import sys


def main():
    ''' Calculate day of week given month, day, year '''

    days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
                    'Thursday', 'Friday', 'Saturday']

    month = int(sys.argv[1])
    day = int(sys.argv[2])
    year = int(sys.argv[3])

    print 'What day was {}/{}/{}?  '.format(day, month, year)

    base_year = year - (14 - month) / 12
    leap = base_year + base_year/4 - base_year/100 + base_year/400
    base_month = month + 12 * ((14 - month) / 12) - 2
    day_of_week = (day + leap + (31 * base_month) / 12) % 7

    print days_of_week[day_of_week]  # Use day_0 as index into days_of_week list


if __name__ == '__main__':
    main()
